#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int maxSum[101][101],d[101][101];
int n; 
int MaxSum(int i,int j)
{
	if(maxSum[i][j]!=0)
		return maxSum[i][j];
	if(i==n)
		maxSum[i][j]=d[i][j];
	else
	{
		int x=MaxSum(i+1,j),y=MaxSum(i+1,j+1);
		maxSum[i][j]=max(x,y)+d[i][j];
	}
	return maxSum[i][j];
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=i;j++)
			{
				cin>>d[i][j];
				maxSum[i][j]=0;
			}
		cout<<MaxSum(1,1)<<endl;
	}
    return 0;
}
